package com.kyzh.core.utils

import android.content.Context
import android.net.ConnectivityManager
import com.gushenge.core.dao.MMKVConsts.selectNetwork
import com.gushenge.core.toast
import com.kyzh.core.R

@Suppress("DEPRECATION")
class NetworkUtil {


    /**
     * 检测网络是否连接
     *
     * @return
     */
    fun checkNetworkState(context: Context){
        //得到网络连接信息
        val manager = context.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
        //去进行判断网络是否连接
        manager.activeNetworkInfo?.let {
            if (!it.isAvailable) {
                context.getString(R.string.pleaseCheckNetwork).toast()
            } else {
                if (selectNetwork) {
                    when(it.type){
                        ConnectivityManager.TYPE_MOBILE->context.getString(R.string.mobileNetworkTips).toast()
                        else->{}
                    }
                }else{

                }
            }

        }
    }


}
